package com.devin.config;

import com.alibaba.dubbo.config.*;
import com.devin.service.EchoService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DubboConsumerConfig {

    @Bean
    public ApplicationConfig getApplicationConfig() {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("dubboConsumer");
        return applicationConfig;
    }

    //<dubbo:registry protocol="zookeeper" address="127.0.0.1:2181"></dubbo:registry>
    @Bean
    public RegistryConfig registryConfig() {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setProtocol("zookeeper");
        registryConfig.setAddress("127.0.0.1:2181");
        return registryConfig;
    }

    @Bean
    public ReferenceConfig<EchoService> helloReferenceConfig() {
        ReferenceConfig<EchoService> serviceConfig = new ReferenceConfig<>();
        serviceConfig.setInterface(EchoService.class);
        serviceConfig.setTimeout(5000);
        serviceConfig.setVersion("*");
        serviceConfig.setRetries(3);
        serviceConfig.setLoadbalance("roundrobin");
        return serviceConfig;
    }

    //	<dubbo:consumer check="false" timeout="5000"></dubbo:consumer>
    @Bean
    public ConsumerConfig consumerConfig() {
        ConsumerConfig consumerConfig = new ConsumerConfig();
        consumerConfig.setCheck(false);
        consumerConfig.setTimeout(5000);
        consumerConfig.setFilter("tpMonitorFilter");
        return consumerConfig;
    }

    //	<dubbo:monitor address="127.0.0.1:7070"></dubbo:monitor>
    @Bean
    public MonitorConfig monitorConfig() {
        MonitorConfig monitorConfig = new MonitorConfig();
        monitorConfig.setAddress("127.0.0.1:7070");
        monitorConfig.setProtocol("registry");
        return monitorConfig;
    }

}
